package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 添加套餐
     * @param setmeal
     */
    /**
     * 添加套餐
     * @param setmeal
     */
    @Insert("insert into itcast_health.t_setmeal (name, code, helpCode, sex, age, price, remark, attention) value " +
            "(#{name},#{code},#{helpCode},#{sex},#{age},#{price},#{remark},#{attention})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void add(Setmeal setmeal);

    /**
     * 添加套餐和检查项的关联关系
     * @param map
     */
    @Insert("insert into itcast_health.t_setmeal_checkgroup (setmeal_id, checkgroup_id) value (#{setmealId},#{checkGroupId})")
    void addSetmealAndCheckItem(Map map);

    /**
     * 编辑套餐根据套餐id
     * @param setmeal
     */
    void edit(Setmeal setmeal);

    /**
     * 删除套餐和检查项的关联关系
     * @param id
     */
    @Delete("delete from itcast_health.t_setmeal_checkgroup where setmeal_id = #{id}")
    void deleteSetmealAndCheckGroupBySetmealId(Integer id);

    /**
     * 根据套餐id查询套餐
     * @param id
     * @return
     */
    @Select("select * from itcast_health.t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    /**
     * 分页查询
     * @param queryString
     * @return
     */
    Page<Setmeal> findPage(String queryString);

    /**
     * 查询所有套餐
     * @return
     */
    @Select("select * from itcast_health.t_setmeal")
    List<Setmeal> getSetmeal();

    @Select("select name from itcast_health.t_setmeal where id = #{setmealId}")
    String getSetmealNameById(Integer setmealId);
}
